<div class="layui-form hisi-search">
    <form action="{:url()}" method="get" id="hisi-table-search">
        <!-- <div class="layui-form-item">
            <label class="layui-form-label">关键词&nbsp;</label>
            <div class="layui-input-inline">
                <input type="text" name="keyword" class="layui-input" lay-verify="required" placeholder="物品名称" />
            </div>
        </div>

        <div class="layui-form-item hisi-search-btn">
            <div class="layui-input-inline">
                <button type="submit" class="layui-btn layui-btn-normal layui-icon layui-icon-search">查询</button>
            </div>
        </div> -->
        <!-- <div class="layui-btn-group fl">
            <a href="{:url('lockers_export_excel')}" class="layui-btn layui-btn-primary layui-icon layui-icon-download-circle">&nbsp;导出</a>
        </div> -->

        <!-- <div class="layui-btn-group fl">
            <button type="button" class="layui-btn" id="test3" name="file"><i class="layui-icon"></i>导入excel</button>
        </div> -->
    </form>
</div>


<table class="layui-hide" id="dataTable" lay-filter='dataTable'></table>

{include file="block/layui" /}
<script type="text/javascript">
    layui.use(['table'], function(){
        var table = layui.table;
        
        table.render({
            elem: '#dataTable'
            ,url:'{:url()}' //数据接口
            ,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter','exports']
            ,cols: [[
            {type:'numbers', title: '序号'}
                ,{field: 'price', title: '红包金额'}
                ,{field: 'rate', title: '红包概率%',edit:'text'}
                ,{field: 'rest_num', title: '库存',edit:'text'}
                ,{field: 'is_send', title: '已送数量'}
            ]]
            ,done: function(){
                if (typeof(layui.global.addTableTool) !== 'undefined') {
                    layui.global.addTableTool();
                }
            }
        });

        table.on('edit(dataTable)', function(obj){
            var $ = layui.jquery
            var newValue = obj.value;
            var changeField = obj.field;
            var id = obj.data.id;
            if(!!isNaN(newValue)){
                layer.alert('概率/库存需为数字');
            }
            $.ajax({
                type:"post",
                url:"{:url('RedRate/setRate')}",
                async:false,
                data:{val:newValue,field:changeField,id:id},
                success:function(data){
                    // console.log(data);
                    if(data.code==200){
                        layer.msg('修改成功');
                    }
                    else{
                        layer.msg(data.msg);
                    }
                },
                error: function(){
                    layer.alert("预警值查询错误！");
                }
            })
            console.log(obj.value);
            console.log(obj.field);
            console.log(obj.data);
        })
        var laydate = layui.laydate;
  
        //执行一个laydate实例
        laydate.render({
            elem: '.datepicker' //指定元素
            ,type: 'datetime'
        });
        laydate.render({
            elem: '.datepicker1' //指定元素
            ,type: 'datetime'
        });
    });
</script>